import axios from '~/axios'

// 登录接口
export function login(params) {
  return axios.post('/admin/login', params)
}

// 获取用户信息
export function getUserInfo() {
  return axios.post('/admin/getinfo')
}

// 退出登录
export function logout() {
  return axios.post('/admin/logout')
}

// 修改密码
export function updatePassword(params) {
  return axios.post('/admin/updatepassword', params)
}

// 获取用户列表
export function getManageList(page, query = {}) {
  let q = []
  for (let key in query) {
    if (query[key]) {
      q.push(`${key}=${encodeURIComponent(query[key])}`)
    }
  }

  let r = q.join('&')
  r = r ? `?${r}` : ''

  return axios.get(`/admin/manager/${page}${r}`)
}

export function updateManagerStatus(id, status) {
  return axios.post(`/admin/manager/${id}/update_status`, {
    status
  })
}


export function createManager(data) {
  return axios.post(`/admin/manager`, data)
}

export function updateManager(id, data) {
  return axios.post(`/admin/manager/${id}`, data)
}

export function deleteManager(id) {
  return axios.post(`/admin/manager/${id}/delete`)
}